package com.firesrc.service.impl;

import java.util.List;
import java.util.UUID;

import com.firesrc.bean.MailDayAmount;
import com.firesrc.bean.MailHost;
import com.firesrc.dao.MailDayAmountDao;
import com.firesrc.dao.impl.MailDayAmountDaoImpl;
import com.firesrc.service.MailDayAmountService;
import com.firesrc.util.SystemUtil;

public class MailDayAmountServiceImpl implements MailDayAmountService {
	private MailDayAmountDao dao;

	public MailDayAmountServiceImpl() {
		dao = new MailDayAmountDaoImpl();
	}

	@Override
	public void add(MailDayAmount mailDayAmount) {
		dao.add(mailDayAmount);
	}

	@Override
	public void put(MailDayAmount mailDayAmount) {
		if (dao.isTodayExist(mailDayAmount.getUserName())) {
			dao.updateAmount(mailDayAmount);
		} else {
			dao.add(mailDayAmount);
		}
	}

	@Override
	public void put(MailHost mailHost) {
		if (!dao.isTodayExist(mailHost.getMail())) {
			MailDayAmount amount = new MailDayAmount();
			amount.setId(UUID.randomUUID().toString());
			amount.setUserName(mailHost.getMail());
			amount.setState("0");
			amount.setAmount(0);
			amount.setDayMax(mailHost.getSendDayMaxCount());
			amount.setKind(mailHost.getKind());
			amount.setSendDate(SystemUtil.getCurrentDateYYYYMMDD());
			dao.add(amount);
		}

	}

	@Override
	public List<MailDayAmount> getAllList() {
		return dao.getAllList(new MailDayAmount());
	}

	@Override
	public List<MailDayAmount> getTodayList() {
		return dao.getTodayList();
	}
}
